package smartq.DB;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;

public class ServiceQ {
	
	public ServiceQ() {
		Q = CustomerPhonenumber = CustomerName = Status = Table = StartTime = EndTime = WaitTime = CustomerNumber = "";
	 }	
    public ServiceQ(
            String OID,
            String UsrOpt,
            String IsActive,
            String IsDeleted,
            
            String Q,
            String CustomerPhonenumber,
            String CustomerName,
            String Status,
            String Table,
            String StartTime,
            String EndTime,
            String WaitTime,
            String CustomerNumber
            )
    
   {
        this.OID 					= OID;
        this.UsrOpt 				= UsrOpt;
        this.IsActive 				= IsActive;
        this.IsDeleted 				= IsDeleted;
        
        this.Q 						= Q;
        this.CustomerPhonenumber 	= CustomerPhonenumber;
        this.CustomerName 			= CustomerName;
        this.Status 				= Status;
        this.Table   				= Table;
        this.StartTime   			= StartTime;
        this.EndTime   				= EndTime;
        this.WaitTime 				= WaitTime;
        this.CustomerNumber 		= CustomerNumber;
        

    }
    //-------------------- Variable -------------------------
    private String OID,
    		UsrOpt,
    		IsActive,
    		IsDeleted,
    		
    		Q,
    		CustomerPhonenumber,
    		CustomerName,
    		Status,
    		Table,
    		StartTime,
    		EndTime,
    		WaitTime,
    		CustomerNumber;
            
    
    Connect con = new Connect(); 
    Connection conn = con.Connect();
    ResultSet rs = null;

    // -------------------- GET-SET -------------------------
    
    public String getOID() {
		return OID;
	}
	public String getCustomerNumber() {
		return CustomerNumber;
	}
	public void setCustomerNumber(String customerNumber) {
		CustomerNumber = customerNumber;
	}
	public void setOID(String oID) {
		OID = oID;
	}
	public String getUsrOpt() {
		return UsrOpt;
	}
	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}
	public String getIsActive() {
		return IsActive;
	}
	public void setIsActive(String isActive) {
		IsActive = isActive;
	}
	public String getIsDeleted() {
		return IsDeleted;
	}
	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}
	public String getQ() {
		return Q;
	}
	public void setQ(String q) {
		Q = q;
	}
	public String getCustomerPhonenumber() {
		return CustomerPhonenumber;
	}
	public void setCustomerPhonenumber(String customerPhonenumber) {
		CustomerPhonenumber = customerPhonenumber;
	}
	public String getCustomerName() {
		return CustomerName;
	}
	public void setCustomerName(String customerName) {
		CustomerName = customerName;
	}
	public String getStatus() {
		return Status;
	}
	public void setStatus(String status) {
		Status = status;
	}
	public String getTable() {
		return Table;
	}
	public void setTable(String table) {
		Table = table;
	}
	public String getStartTime() {
		return StartTime;
	}
	public void setStartTime(String startTime) {
		StartTime = startTime;
	}
	public String getEndTime() {
		return EndTime;
	}
	public void setEndTime(String endTime) {
		EndTime = endTime;
	}
	public String getWaitTime() {
		return WaitTime;
	}
	public void setWaitTime(String waitTime) {
		WaitTime = waitTime;
	}

   
	//-------------------- SQL ------------------------
    public ResultSet selectServiceQ(String CustomernameSearch,String DateNow) throws Exception {
        String StrSql = "SELECT [OID],"
                + "[LastModified],"
                + "[ModifiedDate],"
                + "[ModifiedTime],"
                + "[ModifiedBy],"
                + "[UserModified],"
                + "[CreatDate],"
                + "[CreatTime],"
                + "[CreatedBy],"
                + "[UserCreate],"
                + "[IsActive],"
                + "[IsDeleted],"
                
                + "[Q],"
                + "[CustomerPhonenumber],"
                + "[CustomerName],"
                + "[Status],"
                + "[Table],"
                + "[StartTime],"
                + "[EndTime],"
                + "[WaitTime],"
                + "[CustomerNumber] "
                
  				+ "FROM [Project_NFC].[dbo].[udfServiceQ]() "
  
                + "WHERE [IsDeleted]='0' "; 

        if (!CustomernameSearch.equals("")) {
            StrSql += " AND [CustomerFirstName] LIKE '%" + CustomernameSearch + "%' OR [CustomerPhonenumber] LIKE '%" + CustomernameSearch + "%' " ;
        }
        
        if (!DateNow.equals("")) {
            StrSql += " AND [OID]  LIKE '%" + DateNow + "%' " ;
        }
        
        StrSql += " ORDER BY CreatTime DESC " ;
        
        return con.selectData(StrSql);
    }

    

    public String OperationData(String OperationType) throws Exception {
        try {
        		conn = con.Connect();
                java.sql.CallableStatement cstmt = conn.prepareCall("{call stpServiceQManagement(?,?,?,?,? ,?,?,?,?,? ,?,?,?,?,? )}");
                
                cstmt.setString(1, OperationType);
                cstmt.setString(2, getOID());
                cstmt.setString(3, getUsrOpt());
                cstmt.setString(4, getIsActive());
                cstmt.setString(5, getIsDeleted());

                cstmt.setString(6, getQ());
                cstmt.setString(7, getCustomerPhonenumber());
                cstmt.setString(8, getCustomerName());
                cstmt.setString(9, getStatus());
                cstmt.setString(10, getTable());
                cstmt.setString(11, getStartTime());
                cstmt.setString(12, getEndTime());
                cstmt.setString(13, getWaitTime());
                cstmt.setString(14, getCustomerNumber());
                
                cstmt.registerOutParameter(15, Types.VARCHAR);
                cstmt.execute();
                return cstmt.getString(15);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
        return null;
    }
}